package com.deduction.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.base.common.persistence.Page;
import com.base.model.ViewSelectModel;
import com.company.model.CompanyProject;
import com.company.service.ProjectManageService;

@Controller
public class DeductionController {
	public static final String toDeductionView = "/deduction";
	public static final String projectList = "/deduction/project/list";
	//public static final String projectList = "/company/employee/list";

	// 页面路径
	public static final String deductionPage = "/deduction/index";
	@Autowired
	ProjectManageService projectManageService;
	
	@RequestMapping(value = toDeductionView, method = RequestMethod.POST)
	public ModelAndView toEmployeeView() {
		ModelAndView mv = new ModelAndView(deductionPage);
		return mv;
	}
	
	
	@ResponseBody
	@RequestMapping(value = projectList, method = RequestMethod.POST)
	public List projectList(HttpServletRequest req, HttpServletResponse res) {
		String userId = req.getSession().getAttribute("userId").toString();
		List<CompanyProject> list = null;
		try {
			list = projectManageService.findProjectByCompanyId(userId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		List<ViewSelectModel> returnList = null;
		if (list != null && list.size() > 0) {
			returnList = new ArrayList<ViewSelectModel>(list.size());
			ViewSelectModel selectModel = new ViewSelectModel();
			selectModel.setName("请选择");
			selectModel.setValue("0");
			returnList.add(selectModel);
			for (CompanyProject companyProject : list) {
				selectModel = new ViewSelectModel();
				selectModel.setName(companyProject.getProjectName());
				selectModel.setValue(companyProject.getId());
				returnList.add(selectModel);
			}
		}
		return returnList;
	}
}
